Adding some more judges, here and there.
[and.git] / SPOJ / FILRTEST - 7423. File Recover Testing / filrtest.cpp
blobf9ccfba7d7f8154747be67556de586f3738f19f4
1 using namespace std;
2 #include <cstdio>
3 #include <cstring>
5 const int MAXN = 1000010;
6 char s[MAXN];
7 int border[MAXN];
9 int maximum_repetitions(int n, int k) {
10 if (k < n) return 0;
12 border[0] = -1;
13 for (int i = 0; i < n; ++i) {
14 border[i+1] = border[i];
15 while (border[i+1] > -1 and s[border[i+1]] != s[i]) border[i+1] = border[border[i+1]];
16 border[i+1]++;
19 return 1 + (k - n) / (n - border[n]);
22 int main(){
23 int k;
24 while (scanf("%d %s", &k, s) == 2) {
25 if (k == -1) break;
26 int n = strlen(s);
27 printf("%d\n", maximum_repetitions(n, k));
29 return 0;